<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: mslaria $ ($Date: 2007/07/24 14:00:35 $)
// $RCSfile: winapp_chat.php,v $ : $Revision: 1.32 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

require_once ("./modules/livesupport/functions_livesupport.php");


/**
* ###############################################
* STAFF ACCEPTS A CHAT
* ###############################################
*/
if($eventaction == 'acceptchat') {
	require_once ("./includes/functions_xml.php");
	$xml = new XML;
	
	$xml->addParentTag("swiftwinapp");
		$xml->addTag('sessionid', $_SWIFT["sessionid"]);
		$xml->addTag("chatsessionid", $_GET["chatsessionid"]);
		$visitorSessionId = $_GET["visitorsessionid"];
		//$xml->addTag("visitorsessionid", $_GET["visitorsessionid"]);
		$xml->addTag("staffname", $_SWIFT["staff"]["fullname"]);
		
		$fullname = "";
		$email = "";
		$department = "";
		$refreshinterval = "";
		$chatchildid = "";
		
		$_chatobject = getChatObjectFromSession($_GET["chatsessionid"]);
		if ($_chatobject["chatobjectid"] != "")
		{
			// How many chat childs do we have?
			$childcount = getChatChildCount($_chatobject["chatobjectid"]);
	
			if ($childcount["totalitems"] == 0)
			{
				// Set the staff id, staffname etc because we are just accepting a chat
				$_updstaffid = $_SWIFT["staff"]["staffid"];
				$_updstaffname = $_SWIFT["staff"]["fullname"];
			} else {
				$extendedquery = "";
				// Enter the CHATENTER action as we are in a conference
				
				if (($childcount["totalitems"] >= 1 && $_chatobject["chattype"] == CHAT_CLIENT) || ($childcount["totalitems"] >= 2 && $_chatobject["chattype"] == CHAT_STAFF))
				{
					$conference = true;
				}
				
				if ($conference)
				{
					submitChatAction($_chatobject["chatobjectid"], SUBMIT_STAFF, ACTION_CHATENTER, $_SWIFT["staff"]["fullname"]);				
				}
			}
	
	
			// Lets accept the chat
			if ($_chatobject["chattype"] == CHAT_STAFF && $_chatobject["userid"] == $_SWIFT["staff"]["staffid"])
			{
				// Dont accept the chat if this user initiated it, wait for other user
			} else {
				updateChatStatus($_chatobject["chatobjectid"], CHAT_INCHAT, $_updstaffid, $_updstaffname);
			}
	
			// Insert the chat child id
			$chatchildid = buildHash();
			$dbCore->query("INSERT INTO `". TABLE_PREFIX ."chatchilds` (`chatchildid`, `chatobjectid`, `staffid`, `dateline`) VALUES('". $chatchildid ."', '". $dbCore->escape($_chatobject["chatobjectid"]) ."', '". $dbCore->escape($_SWIFT["staff"]["staffid"]) ."', '". DATENOW ."');");
	
	//		echo "INSERT INTO `". TABLE_PREFIX ."chatchilds` (`chatchildid`, `chatobjectid`, `staffid`, `dateline`) VALUES('". $chatchildid ."', '". $dbCore->escape($_chatobject["chatobjectid"]) ."', '". $dbCore->escape($_SWIFT["staff"]["staffid"]) ."', '". DATENOW ."');";
			
			//$template->assign("chatchildid", $chatchildid);
	
			if ($_chatobject["staffid"] == $_SWIFT["staff"]["staffid"] && $_chatobject["chattype"] == CHAT_STAFF)
			{
				$fullname = $_chatobject["userfullname"];
				$email = $_chatobject["useremail"];
				$visitorSessionId = $_SWIFT["staffcache"][$_chatobject["userid"]]["username"];
				//$template->assign("fullname", $_chatobject["userfullname"]);
				//$template->assign("email", $_chatobject["useremail"]);		
			} else if ($_chatobject["userid"] == $_SWIFT["staff"]["staffid"] && $_chatobject["chattype"] == CHAT_STAFF) {
				$fullname = $_chatobject["staffname"];
				$email = $_SWIFT["staffcache"][$_chatobject["staffid"]]["email"];
				$visitorSessionId = $_SWIFT["staffcache"][$_chatobject["staffid"]]["username"];
				//$template->assign("fullname", $_chatobject["staffname"]);
				//$template->assign("email", $_SWIFT["staffcache"][$_chatobject["staffid"]]["email"]);
			} else {
				$fullname = $_chatobject["userfullname"];
				$email = $_chatobject["useremail"];
				
				//$template->assign("fullname", $_chatobject["userfullname"]);
				//$template->assign("email", $_chatobject["useremail"]);			
			}
			$department = $_chatobject["departmenttitle"];
			//$template->assign("department", $_chatobject["departmenttitle"]);
	
			$refreshinterval = $_SWIFT["settings"]["livesupport_clientchatrefresh"]*1000;
			//$template->assign("refreshinterval", $_SWIFT["settings"]["livesupport_clientchatrefresh"]*1000);
			//echo $template->displayTemplate("winappchatcontentframe.tpl");
		}

		$xml->addTag("visitorsessionid", $visitorSessionId);
		$xml->addTag("chatchildid", $chatchildid);
		$xml->addTag("fullname", $fullname);
		$xml->addTag("email", $email);
		$xml->addTag("department", $department);
		$xml->addTag("refreshinterval", $refreshinterval);
		
	$xml->endTag("swiftwinapp");
	$xml->echoXMLUTFWinapp();
	//die;

/**
* ###############################################
* STAFF ACCEPTS A CHAT
* ###############################################
*/
} else if ($eventaction == "startstaffchat") {
	$template->assign("sessionid", $_SWIFT["sessionid"]);
	$template->assign("chatsessionid", $_GET["chatsessionid"]);
	$template->assign("visitorsessionid", $_GET["visitorsessionid"]);
	$template->assign("staffname", $_SWIFT["staff"]["fullname"]);

	$_chatobject = getChatObjectFromSession($_GET["chatsessionid"]);

	if ($_chatobject["chatobjectid"] != "")
	{
		// How many chat childs do we have?
		$childcount = getChatChildCount($_chatobject["chatobjectid"]);

		if ($childcount["totalitems"] == 0)
		{
			// Set the staff id, staffname etc because we are just accepting a chat
			$_updstaffid = $_SWIFT["staff"]["staffid"];
			$_updstaffname = $_SWIFT["staff"]["fullname"];
		} else {
			$extendedquery = "";
			// Enter the CHATENTER action as we are in a conference
			
			if (($childcount["totalitems"] >= 1 && $_chatobject["chattype"] == CHAT_CLIENT) || ($childcount["totalitems"] >= 2 && $_chatobject["chattype"] == CHAT_STAFF))
			{
				$conference = true;
			}
			
			if ($conference)
			{
				submitChatAction($_chatobject["chatobjectid"], SUBMIT_STAFF, ACTION_CHATENTER, $_SWIFT["staff"]["fullname"]);				
			}
		}


		// Lets accept the chat
		if ($_chatobject["chattype"] == CHAT_STAFF && $_chatobject["userid"] == $_SWIFT["staff"]["staffid"])
		{
			// Dont accept the chat if this user initiated it, wait for other user
		} else {
			updateChatStatus($_chatobject["chatobjectid"], CHAT_INCHAT, $_updstaffid, $_updstaffname);
		}

		// Insert the chat child id
		$chatchildid = buildHash();
		$dbCore->query("INSERT INTO `". TABLE_PREFIX ."chatchilds` (`chatchildid`, `chatobjectid`, `staffid`, `dateline`) VALUES('". $chatchildid ."', '". $dbCore->escape($_chatobject["chatobjectid"]) ."', '". $dbCore->escape($_SWIFT["staff"]["staffid"]) ."', '". DATENOW ."');");

//		echo "INSERT INTO `". TABLE_PREFIX ."chatchilds` (`chatchildid`, `chatobjectid`, `staffid`, `dateline`) VALUES('". $chatchildid ."', '". $dbCore->escape($_chatobject["chatobjectid"]) ."', '". $dbCore->escape($_SWIFT["staff"]["staffid"]) ."', '". DATENOW ."');";

		$template->assign("chatchildid", $chatchildid);

		if ($_chatobject["staffid"] == $_SWIFT["staff"]["staffid"] && $_chatobject["chattype"] == CHAT_STAFF)
		{
			$template->assign("fullname", $_chatobject["userfullname"]);
			$template->assign("email", $_chatobject["useremail"]);		
		} else if ($_chatobject["userid"] == $_SWIFT["staff"]["staffid"] && $_chatobject["chattype"] == CHAT_STAFF) {
			$template->assign("fullname", $_chatobject["staffname"]);
			$template->assign("email", $_SWIFT["staffcache"][$_chatobject["staffid"]]["email"]);
		} else {
			$template->assign("fullname", $_chatobject["userfullname"]);
			$template->assign("email", $_chatobject["useremail"]);			
		}
		$template->assign("department", $_chatobject["departmenttitle"]);

		$template->assign("refreshinterval", $_SWIFT["settings"]["livesupport_clientchatrefresh"]*1000);
		echo $template->displayTemplate("winappchatcontentframe.tpl");
	}


/**
* ###############################################
* STAFF SUBMITTED A CHAT MESSAGE
* ###############################################
*/
} else if ($eventaction == "postchatmessage") {
	if (trim($_REQUEST["message"]) != "")
	{
		submitChatMessage($_REQUEST["chatsessionid"], MESSAGE_STAFF, iif($_REQUEST["base64"]=="true", urldecode($_REQUEST["message"]), base64_encode($_REQUEST["message"])), true);
	}

	echoWinappData("1");




/**
* ###############################################
* STAFF REFUSED A CHAT
* ###############################################
*/
} else if ($eventaction == "refusechat") {

	if (trim($_REQUEST["chatsessionid"]) != "")
	{
		$_chatobject = getChatObjectFromSession($_REQUEST["chatsessionid"]);

		if ($_chatobject["chatobjectid"] != "")
		{
			$roundrobinstaffid = getRoundRobinStaff($_chatobject["departmentid"], array($_SWIFT["staff"]["staffid"]));
			
			if (!$roundrobinstaffid || $roundrobinstaffid == $_SWIFT["staff"]["staffid"])
			{
				// Change the status because no other staff is online
				updateChatStatus($_chatobject["chatobjectid"], CHAT_NOANSWER);
			} else {
				updateChatStatus($_chatobject["chatobjectid"], CHAT_INCOMING, $roundrobinstaffid, $_SWIFT["staffcache"][$roundrobinstaffid]["fullname"]);
			}

			echoWinappData("1");
		} else {
			echoWinappData("0");
		}
	} else {
		echoWinappData("0");
	}


/**
* ###############################################
* CALLED WHEN STAFF IS TYPING A MESSAGE
* ###############################################
*/
} else if ($eventaction == "usertyping") {
	if (trim($_REQUEST["chatsessionid"]) != "" && $_SWIFT["settings"]["livesupport_enableuseristyping"] == 1)
	{
		$_chatobject = getChatObjectFromSession($_REQUEST["chatsessionid"]);

		if ($_chatobject["chatobjectid"] != "")
		{
			submitChatAction($_chatobject["chatobjectid"], SUBMIT_STAFF, ACTION_TYPING, $_SWIFT["staff"]["fullname"]);
		}
	}
	echoWinappData("1");

/**
* ###############################################
* CALLED WHEN STAFF ENDS A CHAT SESSION
* ###############################################
*/
} else if ($eventaction == "chatendsession") {
	if (trim($_REQUEST["chatsessionid"]) != "")
	{
		$_chatobject = getChatObjectFromSession($_REQUEST["chatsessionid"]);

		if ($_chatobject["chatobjectid"] != "")
		{
			endStaffChat($_chatobject["chatobjectid"]);
		}
	}

	echoWinappData("1");





/**
* ###############################################
* CALLED WHEN STAFF PUSHES A NEW PAGE TO VISITOR
* ###############################################
*/
} else if ($eventaction == "pushpagevisitor") {
	if (trim($_REQUEST["url"]) != "" && trim($_REQUEST["chatsessionid"]) != "")
	{
		$_chatobject = getChatObjectFromSession($_REQUEST["chatsessionid"]);

		if ($_chatobject["chatobjectid"] != "")
		{
			submitChatAction($_chatobject["chatobjectid"], SUBMIT_STAFF, ACTION_URL, urldecode($_REQUEST["url"]));
		}
	}
	echoWinappData("1");



/**
* ###############################################
* PUSH AN IMAGE TO VISITOR
* ###############################################
*/
} else if ($eventaction == "pushimagevisitor") {
	if (trim($_REQUEST["url"]) != "" && trim($_REQUEST["chatsessionid"]) != "")
	{
		$_chatobject = getChatObjectFromSession($_REQUEST["chatsessionid"]);

		if ($_chatobject["chatobjectid"] != "")
		{
			submitChatAction($_chatobject["chatobjectid"], SUBMIT_STAFF, ACTION_IMAGE, urldecode($_REQUEST["url"]));
		}
	}
	echoWinappData("1");



/**
* ###############################################
* PUSH CODE TO VISITOR
* ###############################################
*/
} else if ($eventaction == "staffpushcode") {
	if (trim($_REQUEST["code"]) != "" && trim($_REQUEST["chatsessionid"]) != "")
	{
		$_chatobject = getChatObjectFromSession($_REQUEST["chatsessionid"]);

		if ($_chatobject["chatobjectid"] != "")
		{
			submitChatAction($_chatobject["chatobjectid"], SUBMIT_STAFF, ACTION_CODE, urldecode($_REQUEST["code"]));
		}
	}
	echoWinappData("1");



/**
* ###############################################
* EMAIL CHAT CONVO
* ###############################################
*/
} else if ($eventaction == "emailchat") {
	if (trim($_REQUEST["chatsessionid"]) != "" && trim($_REQUEST["emailaddress"]) != "")
	{
		$conference = false;

		$_chatobject = getChatObjectFromSession($_REQUEST["chatsessionid"]);

		if ($_chatobject["chatobjectid"] != "")
		{
			require_once ("./includes/functions_mail.php");
			require_once ("./includes/functions_users.php");
			require_once ("./includes/functions_departments.php");
			$departments = new Departments;
			$mail = new SWIFT_Mail();

			$template->setGroup(1);

			$dbCore->query("SELECT * FROM `". TABLE_PREFIX ."chatdata` WHERE `chatobjectid` = '". $_chatobject["chatobjectid"] ."';");
			$convo = array();
			while ($dbCore->nextRecord())
			{
				$convo = array_merge($convo, unserialize($dbCore->Record["contents"]));
			}

			foreach ($convo as $key=>$val)
			{
				if ($val["base64"] == true)
				{
					$convo[$key]["message"] = base64_decode($val["message"]);
					$_messagestore .= $convo[$key]["message"];
				}
			}
			$template->assign("conversation", $convo);

			$template->loadLanguageSection("livesupportclient", TEMPLATE_DB);

			$template->assign("clientname", $_chatobject["userfullname"]);
			$template->assign("clientemail", $_chatobject["useremail"]);
			$template->assign("staffname", $_chatobject["staffname"]);
			$template->assign("department", $_chatobject["departmenttitle"]);
			$template->assign("date", date($_SWIFT["settings"]["dt_datetimeformat"], $_chatobject["dateline"]));

			$template->assign("ishtml", false);
			$emailtext = $template->displayTemplate("emailforwardconversation", TEMPLATE_DB);
			$template->assign("ishtml", true);
			$emailhtml = $template->displayTemplate("emailforwardconversation", TEMPLATE_DB);
		
			$mail->setSubject($_SWIFT["language"]["emailconvosubject"]);
			$mail->setData($emailhtml, $emailtext, iif(stristr($_messagestore, '&#'), true, false));

			$mail->sendMail($_REQUEST["emailaddress"], $_SWIFT["settings"]["general_returnemail"], $_SWIFT["staff"]["fullname"]);
		}
	}
	echoWinappData("1");




/**
* ###############################################
* TRANSFER CHAT
* ###############################################
*/
} else if ($eventaction == "transferchat") {
	if (trim($_REQUEST["chatsessionid"]) != "")
	{
		$_chatobject = getChatObjectFromSession($_REQUEST["chatsessionid"]);

		if ($_chatobject["chatobjectid"] != "")
		{
			// Get the other staff's session id
			$_staffsession = $dbCore->queryFetch("SELECT * FROM `". TABLE_PREFIX ."sessions` WHERE `sessiontype` IN ('". SESSION_WINAPP ."', '". SESSION_MONITOR ."') AND `typeid` = '". $dbCore->escape($_REQUEST["totransfer"]) ."';");

			// Transfer the chat ONLY if the other staff is online, dont transfer if hes busy, away or offline
			if ($_staffsession["status"] == STATUS_ONLINE)
			{
				$dbCore->shutdownQuery("UPDATE `". TABLE_PREFIX ."chatobjects` SET `transferfromid` = '". $dbCore->escape($_SWIFT["staff"]["staffid"]) ."', `transfertoid` = '". $dbCore->escape($_REQUEST["totransfer"]) ."', `transferstatus` = '". TRANSFER_PENDING ."', `transfertimeline` = '". DATENOW ."' WHERE `chatobjectid` =  '". $dbCore->escape($_chatobject["chatobjectid"]) ."';");
				echoWinappData("1");
			} else {
				echoWinappData("0");
			}
		} else {
			echoWinappData("0");
		}
	} else {
		echoWinappData("0");
	}



/**
* ###############################################
* PROACTIVE REQUEST CHAT IN WINAPP MENU
* ###############################################
*/
} else if ($eventaction == "proactiverequestchat" && $_REQUEST["visitorsessionid"] != "") {
	$_visitorsession = getVisitorSession($_REQUEST["visitorsessionid"]);

	if (trim($_visitorsession["sessionid"]) != "")
	{
		// Success, we have the visitor data.
		updateSessionStatus($_REQUEST["visitorsessionid"], PROACTIVE_REQUEST);

		doVisitorPull($_REQUEST["visitorsessionid"]);

		echoWinappData("1");
	} else {
		echoWinappData("0");
	}




/**
* ###############################################
* PROACTIVE FORCED CHAT
* ###############################################
*/
} else if ($eventaction == "proactiveforcedchat" && $_REQUEST["visitorsessionid"] != "") {
	$_visitorsession = getVisitorSession($_REQUEST["visitorsessionid"]);

	if (trim($_visitorsession["sessionid"]) != "")
	{
		updateSessionStatus($_REQUEST["visitorsessionid"], PROACTIVE_FORCED);

		doVisitorPull($_REQUEST["visitorsessionid"]);

		echoWinappData("1");
	} else {
		echoWinappData("0");
	}





/**
* ###############################################
* START STAFF TO STAFF CHAT
* ###############################################
*/
} else if ($eventaction == "startstafftostaffchat") {
	// Get any department to which staff or group is assigned to.//Modified by Mahesh.
	$_department = $dbCore->queryFetch("SELECT departments.departmentid, departments.departmentmodule FROM `". TABLE_PREFIX ."departments` AS departments LEFT JOIN `". TABLE_PREFIX ."staffassigns` AS staffassigns ON (staffassigns.departmentid = departments.departmentid) LEFT JOIN `". TABLE_PREFIX ."groupassigns` AS groupassigns ON (groupassigns.departmentid = departments.departmentid) WHERE departments.departmentmodule = '" .MODULE_LIVESUPPORT. "' AND staffassigns.staffid = '". $dbCore->escape($_SWIFT["staff"]["staffid"]) ."'". iif($_SWIFT["staff"]["groupassigns"]==1," OR groupassigns.staffgroupid = '". $dbCore->escape($_SWIFT["staff"]["staffgroupid"]) ."'") .";");
	// No department set?
	if ($_department["departmentid"] == "" && $_department["departmentmodule"] != MODULE_LIVESUPPORT)
	{
		echo $_SWIFT["language"]["staffchaterror"];
		exit;
	} else {
		$departmentid = $_department["departmentid"];
	}

	// Insert the chat object
	$dbCore->query("INSERT INTO `". TABLE_PREFIX ."chatobjects` (`visitorsessionid`, `dateline`, `lastpostactivity`, `userpostactivity`, `staffpostactivity`, `userid`, `userfullname`, `useremail`, `staffid`, `staffname`, `chatstatus`, `transferfromid`, `transfertoid`, `transferstatus`, `transfertimeline`, `roundrobintimeline`, `roundrobinhits`, `departmentid`, `departmenttitle`, `chattype`, `ipaddress`, `isproactive`) VALUES('', '". DATENOW ."', '0', '0', '0', '". $dbCore->escape($_SWIFT["staff"]["staffid"]) ."', '". $dbCore->escape($_SWIFT["staff"]["fullname"]) ."', '". $dbCore->escape($_SWIFT["staff"]["email"]) ."', '". $dbCore->escape($_REQUEST["staffid"]) ."', '". $dbCore->escape($_SWIFT["staffcache"][$_REQUEST["staffid"]]["fullname"]) ."', '". CHAT_INCOMING ."', '0', '0', '0', '0', '". DATENOW ."', '0', '". $departmentid ."', '". $dbCore->escape($_SWIFT["departmentcache"][$departmentid]["title"]) ."', '". CHAT_STAFF ."', '". $dbCore->escape($_SERVER["REMOTE_ADDR"]) ."', '". "0" ."');");

	$chatObjectId = $dbCore->lastInsertId();

	// Insert the chat session
	$chatsessionid = $session->insertSession(SESSION_CHAT, $chatObjectId);
	//Mahesh Slaria:
	$dbCore->query("INSERT INTO `". TABLE_PREFIX ."chatdata` (`chatobjectid`, `contents`) VALUES('". $dbCore->escape($chatObjectId) ."', '". $dbCore->escape(serialize(array())) ."');");

	echoWinappData($chatsessionid);	







/**
* ###############################################
* START VOICE CHAT
* ###############################################
*/
} else if ($eventaction == "startvoicechat") {
	if (trim($_REQUEST["chatsessionid"]))
	{
		$_chatobject = getChatObjectFromSession($_REQUEST["chatsessionid"]);

		if ($_chatobject["chatobjectid"] != "" && $_chatobject["chattype"] == CHAT_STAFF)
		{
			// Get all the chat childs for this chat
			$childcount = 0;
			$_chatchildid = array();
			$dbCore->query("SELECT * FROM `". TABLE_PREFIX ."chatchilds` WHERE `chatobjectid` = '". intval($_chatobject["chatobjectid"]) ."';");
			while ($dbCore->nextRecord())
			{
				if ($dbCore->Record["staffid"] != $_SWIFT["staff"]["staffid"])
				{
					$_chatchildid["chatchildid"] = $dbCore->Record["chatchildid"];
					$_chatchildid["staffid"] = $dbCore->Record["staffid"];
				}
				$childcount++;
			}


			if ($childcount == 2 && $_chatchildid["staffid"] != "")
			{
				submitChatChildAction($_chatobject["chatobjectid"], $_chatchildid["chatchildid"], ACTION_VOICECHAT, array("ip" => $_SERVER["REMOTE_ADDR"], "port" => intval($_REQUEST["port"])));
	
				echoWinappData("1");
			} else {
				echoWinappData("-2");
			}
		} else {
			echoWinappData("-1");
		}
	} else {
		echoWinappData("0");
	}




/**
* ###############################################
* START VIEW SHARE SESSION
* ###############################################
*/
} else if ($eventaction == "startviewshare") {
	if (trim($_REQUEST["chatsessionid"]))
	{
		$_chatobject = getChatObjectFromSession($_REQUEST["chatsessionid"]);
		$_viewshareurl = "http://".iif(empty($_REQUEST["ip"]), $_SERVER["REMOTE_ADDR"], $_REQUEST["ip"]).":".$_REQUEST["port"]."/connect?hash=".urlencode($_REQUEST["hash"]);

		if ($_chatobject["chatobjectid"] != "" && $_chatobject["chattype"] == CHAT_STAFF)
		{
			$childcount = 0;
			$_chatchild = array();
			$dbCore->query("SELECT * FROM `". TABLE_PREFIX ."chatchilds` WHERE `chatobjectid` = '". intval($_chatobject["chatobjectid"]) ."';");
			while ($dbCore->nextRecord())
			{
				if ($dbCore->Record["staffid"] != $_SWIFT["staff"]["staffid"])
				{
					$_chatchild[] = $dbCore->Record["chatchildid"];
				}
				$childcount++;
			}

			foreach ($_chatchild as $key=>$val)
			{
				submitChatChildAction($_chatobject["chatobjectid"], $val, ACTION_VIEWSHARE, array("ip" => $_SERVER["REMOTE_ADDR"], "port" => intval($_REQUEST["port"]), "hash" => $_REQUEST["hash"], "url" => $_viewshareurl, "name" => $_SWIFT["staff"]["fullname"]));
			}

		} else if ($_chatobject["chatobjectid"] != "" && $_chatobject["chattype"] == CHAT_CLIENT) {
			submitChatChildAction($_chatobject["chatobjectid"], "0", ACTION_VIEWSHARE, array("ip" => $_SERVER["REMOTE_ADDR"], "port" => intval($_REQUEST["port"]), "hash" => $_REQUEST["hash"], "url" => $_viewshareurl));
		
		}
	}
	echoWinappData("1");
}

?>